package cn.csxw.openchina.dagger2.presenter;

import java.util.ArrayList;

import cn.csxw.openchina.entity.bean.CommentBean;
import cn.csxw.openchina.entity.bean.OsChinaBean;
import cn.csxw.openchina.ui.fragment.CommentFragment.MoveCommentFragment;
import retrofit2.Call;

/**
 * 动弹模块的新的动弹界面的Presenter类
 */

public class MoveCommentPresenter extends BasePresenter {
    private MoveCommentFragment moveCommentFragment;

    public MoveCommentPresenter(MoveCommentFragment moveCommentFragment) {
        this.moveCommentFragment = moveCommentFragment;
    }

    @Override
    protected void processData(OsChinaBean data) {
        if (data != null) {
            ArrayList<CommentBean> tweets = (ArrayList<CommentBean>) data.comments;
            if(!isRefresh){
                moveCommentFragment.mAdapter.addData(tweets);
            }else{
                moveCommentFragment.mAdapter.setData(tweets);
            }
            isRefresh = false;
            moveCommentFragment.mSrfLayout.setRefreshing(false);  //  刷新完成
            moveCommentFragment.loadMoreCompleted();              //  加载更多完成
        }
    }

    /**
     * @param params
     */
    @Override
    public void callNetWork(Object... params) {

        if(params.length!=4||!(params[0] instanceof Integer)
                ||!(params[1] instanceof Integer)||!(params[2] instanceof Integer)|| !(params[3] instanceof String)){
            throw new IllegalArgumentException("参数必需是int , int ,int,string,四个类型");
        }
            Call<OsChinaBean> moveInfo = mOsChinaServer.getCommentInfo((int)params[0],(int)params[1],(int)params[2], ((String) params[3]));
            moveInfo.enqueue(mCallback);
    }
}
